#include <iostream>
#include <string>
#include <cmath>

int main() {
    std::string p[3];
    std::string c = "";
    int wr = 0;
    int m = 2;
    int f = 0, f1 = 0, f2 = 0;
    int s;

    std::cin >> p[0] >> p[1] >> p[2];

    if (p[0] == "zero") c += "0";
    else if (p[0] == "one") c += "1";
    else if (p[0] == "two") c += "2";
    else if (p[0] == "three") c += "3";
    else if (p[0] == "four") c += "4";
    else if (p[0] == "five") c += "5";
    else if (p[0] == "six") c += "6";
    else if (p[0] == "seven") c += "7";
    else if (p[0] == "eight") c += "8";
    else if (p[0] == "nine") c += "9";
    else {
        std::cout << "Wrong input" << std::endl;
        wr = 1;
    }

    if (p[1] == "zero") c += "0";
    else if (p[1] == "one") c += "1";
    else if (p[1] == "two") c += "2";
    else if (p[1] == "three") c += "3";
    else if (p[1] == "four") c += "4";
    else if (p[1] == "five") c += "5";
    else if (p[1] == "six") c += "6";
    else if (p[1] == "seven") c += "7";
    else if (p[1] == "eight") c += "8";
    else if (p[1] == "nine") c += "9";
    else {
        std::cout << "Wrong input" << std::endl;
        wr = 1;
    }

    if (p[2] == "zero") c += "0";
    else if (p[2] == "one") c += "1";
    else if (p[2] == "two") c += "2";
    else if (p[2] == "three") c += "3";
    else if (p[2] == "four") c += "4";
    else if (p[2] == "five") c += "5";
    else if (p[2] == "six") c += "6";
    else if (p[2] == "seven") c += "7";
    else if (p[2] == "eight") c += "8";
    else if (p[2] == "nine") c += "9";
    else {
        std::cout << "Wrong input" << std::endl;
        wr = 1;
    }

    if (wr == 0) {
        s = std::stoi(c);
        f = 0;

        while (f == 0) {
            m = 2;
            while (m < s) {
                if (s % m == 0) {
                    s = s - 1;
                    break;
                } else if (s % m != 0) {
                    m += 1;
                }
                if (m == (s - 2)) {
                    f = 1;
                    break;
                }
            }
            f1 += 1;
        }

        s = std::stoi(c);
        f = 0;
        while (f == 0) {
            m = 2;
            while (m < s) {
                if (s % m == 0) {
                    s += 1;
                    break;
                } else if (s % m != 0) {
                    m += 1;
                }
                if (m == s - 2) {
                    f = 1;
                    break;
                }
            }
            f2 += 1;
        }

        f1 = f1 - 1;
        f2 = f2 - 1;
        if (f1 < f2) {
            std::cout << std::stoi(c) - f1 << std::endl;
        } else if (f1 > f2) {
            std::cout << std::stoi(c) + f2 << std::endl;
        } else if (f1 == f2) {
            std::cout << std::stoi(c) - f1 << std::endl;
    }

    return 0;
}
}

